package com.huc.netty.serial;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author huc
 * @version 1.0
 * @note
 * @date 2021/9/16 10:18
 */
public class SerializerManager {

    private final static ConcurrentHashMap<Byte, ISerializer> serializer = new ConcurrentHashMap<>(2);

    static {
        ISerializer json = new JsonSerializer();
        ISerializer java = new JavaSerializer();
        serializer.put(json.getType(), json);
        serializer.put(java.getType(), java);
    }

    /**
     * 根据类型获取序列化类型
     *
     * @param key
     * @return
     */
    public static ISerializer getSerializer(byte key) {
        ISerializer iSerializer = serializer.get(key);
        if (serializer == null) {
            return new JavaSerializer();
        }
        return iSerializer;
    }

}
